//
//  ConfigureMessageViewController.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/1/21.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "ConfigureMessageViewController.h"

#define kCellHeight 85 / 2

#define kReceiveMessageViewTopMargin 55 / 2
#define kReceiveMessageViewBottomMargin 85 / 2
#define kNoticeLabelHeight 50 / 2
#define kLabelLeftMargin 30 / 2
#define kSwitchWidth 100 / 2
#define kSwitchTopMargin 10 / 2

#define kBigFontSize 14
#define kSmallFontSize 12

@interface ConfigureMessageViewController ()

@end

@implementation ConfigureMessageViewController

{
    UIView *_receiveMessageView;
    UILabel *_receiveMessageNoticeLabel;
    UILabel *_noticeLabel;
    UIView *_noticeView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customNav];
    [self customMainView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.tabBarController.tabBar.hidden = NO;
}

#pragma mark - Custom User Interface

- (void)customNav{
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(bbiClick:)];
    self.navigationItem.leftBarButtonItem = bbi;
    self.title = @"消息设置";
}

- (void)customMainView{
    
    self.view.backgroundColor = RGB_COLOR(@"#f6f6f6");
    
    _receiveMessageView = [[UIView alloc] initWithFrame:CGRectMake(0, kReceiveMessageViewTopMargin + kNavigationBarHeight, UISCREENWIDTH, kCellHeight)];
    _receiveMessageView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kLabelLeftMargin, 0, 100, kCellHeight)];
    titleLabel.text = @"接受新消息通知";
    titleLabel.font = [UIFont systemFontOfSize:kBigFontSize];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    CGRect rect = [titleLabel textRectForBounds:titleLabel.bounds limitedToNumberOfLines:1];
    titleLabel.frame = CGRectMake(kLabelLeftMargin, 0, rect.size.width, kCellHeight);
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.right, 0, UISCREENWIDTH - 2 * kLabelLeftMargin - rect.size.width, kCellHeight)];
    detailLabel.textAlignment = NSTextAlignmentRight;
    detailLabel.font = [UIFont systemFontOfSize:kSmallFontSize];
    [_receiveMessageView addSubview:titleLabel];
    [_receiveMessageView addSubview:detailLabel];
    
    _receiveMessageNoticeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kLabelLeftMargin, _receiveMessageView.bottom, _receiveMessageView.width - 2 *kLabelLeftMargin, kNoticeLabelHeight)];
    _receiveMessageNoticeLabel.text = @"要开启或停用，您可以在设置>金马甲手动设置";
    _receiveMessageNoticeLabel.backgroundColor = [UIColor clearColor];
    _receiveMessageNoticeLabel.textColor = RGB_COLOR(@"#c9c9c9");
    _receiveMessageNoticeLabel.font = [UIFont systemFontOfSize:kSmallFontSize];
    
    _noticeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_receiveMessageNoticeLabel.left, _receiveMessageNoticeLabel.bottom + kReceiveMessageViewBottomMargin, _receiveMessageNoticeLabel.width, kNoticeLabelHeight)];
    _noticeLabel.textColor = RGB_COLOR(@"#555555");
    _noticeLabel.text = @"提示音效";
    _noticeLabel.font = [UIFont systemFontOfSize:kBigFontSize];
    
    _noticeView = [[UIView alloc] initWithFrame:CGRectMake(_receiveMessageView.left, _noticeLabel.bottom, _receiveMessageView.width, 2 * kCellHeight)];
    _noticeView.backgroundColor = [UIColor whiteColor];
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(kLabelLeftMargin, 0, 100, kCellHeight)];
    label1.text = @"铃声提醒";
    label1.font = [UIFont systemFontOfSize:kBigFontSize];
    CGRect rect1 = [label1 textRectForBounds:label1.bounds limitedToNumberOfLines:1];
    label1.frame = CGRectMake(kLabelLeftMargin, 0, rect1.size.width, kCellHeight);
    UISwitch *switch1 = [[UISwitch alloc] initWithFrame:CGRectMake(UISCREENWIDTH - kLabelLeftMargin - kSwitchWidth, kSwitchTopMargin, kSwitchWidth, kCellHeight - 2 * kSwitchTopMargin)];
    UIView *separateView = [[UIView alloc] initWithFrame:CGRectMake(kLabelLeftMargin, label1.bottom, UISCREENWIDTH - 2 * kLabelLeftMargin, 0.5)];
    separateView.backgroundColor = RGB_COLOR(@"#c9c9c9");
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(kLabelLeftMargin, kCellHeight, 100, kCellHeight)];
    label2.text = @"震动提醒";
    label2.font = [UIFont systemFontOfSize:kBigFontSize];
    CGRect rect2 = [label2 textRectForBounds:label2.bounds limitedToNumberOfLines:1];
    label2.frame = CGRectMake(kLabelLeftMargin, kCellHeight, rect2.size.width, kCellHeight);
    UISwitch *switch2 = [[UISwitch alloc] initWithFrame:CGRectMake(UISCREENWIDTH - kLabelLeftMargin - kSwitchWidth, label1.bottom + kSwitchTopMargin, kSwitchWidth, kCellHeight - 2 * kSwitchTopMargin)];
    [_noticeView addSubview:label1];
    [_noticeView addSubview:switch1];
    [_noticeView addSubview:separateView];
    [_noticeView addSubview:label2];
    [_noticeView addSubview:switch2];
    
    [self.view addSubview:_receiveMessageView];
    [self.view addSubview:_receiveMessageNoticeLabel];
    [self.view addSubview:_noticeLabel];
    [self.view addSubview:_noticeView];
}

#pragma mark - Action 

- (void)bbiClick:(UIBarButtonItem *)bbi{
    [self.navigationController popViewControllerAnimated:NO];
}

@end
